<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./10.9 vue day08/jquery-3.5.0.min.js"></script>
    <script src="./10.9 vue day08/axios.min.js"></script>
    <script>
        var token='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJOUT09Iiwic3ViIjoiYWRtaW4xIiwiaXNzIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJpYXQiOjE2MDIzNDAxMDQsImF1ZCI6InJlc3RhcGl1c2VyIiwiZXhwIjoxNjAyNTEyOTA0LCJuYmYiOjE2MDIzNDAxMDR9.FCHjFy3Xe8v9Dqg9yF2pbEa-1njilVerm9QeKNLqc-g';
        //1.全局默认配置
        axios.defaults.baseURL = 'http://47.94.229.139:7788';
        axios.defaults.headers.common['Authorization'] = token;
        axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
        //2.响应拦截
        axios.interceptors.response.use(
            function (response) {	
                // 对响应数据做点什么
                if(response.data.status==200){
                    return response.data;
                }else{
                    alert(response.data.message);
                    return Promise.reject(response.data);
                }	
                
        });
            
        //3.请求封装
            var request={
                get:function(url,params){
                    return axios.get(url,{
                        params
                    })
                },
                post:function(url,data){
                    return axios.post(url,$.param(data))
                },
                postJSON:function(url,data){
                    return axios.post(url,data,{
                        "contentType":"application/json"
                    })
                }
            }
        //4.发送请求-处理数据
            // request.get('/category/findAll').then((response)=>{
            //     console.log('category-get:',response)
            // });
            // request.get('/baseUser/pageQuery',{
            //     page:1,
            //     pageSize:10
            // }).then((response)=>{
            //     console.log('user-get',response)
            // })
            // request.post('/baseUser/saveOrUpdate',{
            //     username:'tom-03',
            //     password:'tom-03'
            // }).then((response)=>{
            //     console.log('post:',response)
            // })
            request.postJSON('/user/login',{
                "password": "123321",
                "username": "admin1"
            }).then((response)=>{
                console.log('postJSON:',response)
            })
    </script>
</head>
<body>
    
</body>
</html>